package model;
/**
 * @author Darko Martinovikj
 * @version 1.0 01.03.2013
 * 
 * Class representing a hash table for storing all the transitions and their type: controllable,uncontrollable
 *  */
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

/**
 * Class for storting all the transitions names and their type
 * @author DarkoLaptop2
 *
 */
public class TransitionHashTable {

private HashMap<String,Boolean> table;
	
	/**
	 * Constructor of the class. Creates a new hash table
	 *
	 */
	public TransitionHashTable() {
		table=new HashMap<String,Boolean>();
	}
	
	/**
	 * Method for transition insertion. The transition name and if is controllable must be specified
	 *
	 *@param String transitionName - name of the transition
	 *@param boolean isControllable - true if the transition is controllable, false if is uncontrollable
	 */
	public void insertTransition(String transitionName,boolean isControllable){
		table.put(transitionName, isControllable);
	}
	
	/**
	 * Method for transition deletion. The transition name must be specified
	 *
	 *@param String transitionName - name of the transition which will be deleted
	 */
	public void removeTransition(String transitionName){
		table.remove(transitionName);
	}
	
	
	/**
	 * Method for returning all of the transitions as Array of string
	 *
	 *@return String[] - Arrays of string, representing transitions name
	 */
	public String[] getAllTransitions(){
		String[] allTransitions=new String[table.keySet().size()];
		int i=0;
		for(String element:table.keySet())
			allTransitions[i++]=element;
		return allTransitions;
	}
	
	/**
	 * Method for returning all of the transitions which are controllable as Array of string
	 *
	 *@return String[] - Arrays of string, representing transitions name
	 */
	public String[] getAllControllableTransitions(){
		LinkedList<String> allTransitions=new LinkedList<String>();
		for(Map.Entry<String,Boolean> element:table.entrySet())
			if(element.getValue())
				allTransitions.addLast(element.getKey());
		String[] allTransitionsArray=new String[allTransitions.size()];
		allTransitions.toArray(allTransitionsArray);
		return allTransitionsArray;
	}
	
	/**
	 * Method for returning all of the transitions which are uncontrollable as Array of string
	 *
	 *@return String[] - Arrays of string, representing transitions name
	 */
	public String[] getAllUncontrollableTransitions(){
		LinkedList<String> allTransitions=new LinkedList<String>();
		for(Map.Entry<String,Boolean> element:table.entrySet())
			if(!element.getValue())
				allTransitions.addLast(element.getKey());
		String[] allTransitionsArray=new String[allTransitions.size()];
		allTransitions.toArray(allTransitionsArray);
		return allTransitionsArray;
	}
	
	/**
	 * Method for returning if a given transition is Controllable. If that transition doesn't exist returns null
	 *
	 *@return Boolean - if the transition is Controllable, or null if that transition doesn't exist
	 */
	public Boolean isControllableTransition(String transitionName){
		return table.get(transitionName);
	}
	
	public void setUncontrollableTransition(String transitionName)
	{
		table.put(transitionName, false);
	}
}
